<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>平均等待时间</title>
</head>

<body>
  <script>
    function arr(customers) {
      let time = 0;//当前时间
      let timenum = 0;//所有顾客等待总时间
      const man = customers.length;//顾客人数
      for (let i = 0; i < man; ++i) {
        if (time <= customers[i][0]) {
          time = customers[i][0];//在顾客到来之前，或者顾客刚好到了，则time等于顾客到的时间(开始做菜)
          timenum += customers[i][1];//customers[i][1]则为当前顾客的等待时间
        } else {//当前时间顾客还没到
          timenum += time - customers[i][0] + customers[i][1];
        }
        time += customers[i][1];
      }
      return timenum / man;
    };
    console.log(arr([[1, 2], [2, 5], [4, 3]]));
  </script>
</body>

</html>